# -*- coding: utf-8 -*-

# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://doc.scrapy.org/en/latest/topics/item-pipeline.html

import pymongo
class DoubanPipeline(object):
    def open_spider(self,spider):
        '''
        1、连接mongodb数据
        :param spider:
        :return:
        '''
        import pymongo
        client = pymongo.MongoClient("localhost", 27017)
        db = client.test
        self.db = db


    def process_item(self, item, spider):

        x = item
        #r = self.db.my_collection.insert(item._values)

        r = self.db.my_collection.update({'movie_info': {'urlid': x['movie_info']['urlid']}}, x, True)
        return item
